// @FileName  :2024_T1.c
// @Time      :2024/5/10 22:52
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>
# include <ctype.h>

#define max2(a, b) (a>b?a:b)
char all[300][100];
char *ans1, *ans3;

char *getans(char *a, char *b) {
    char *res = (char *) malloc(sizeof(char) * 100), *tmp;
    int len = max2(strlen(a), strlen(b));
    int i = 0, j = 0, k = 0;
    if (strlen(a) < len) {
        tmp = a;
        a = b;
        b = tmp;
    }
    for (; i < len;) {
        if (j < strlen(b) && a[i] == b[j]) i++, j++;
        else res[k++] = a[i++];
    }
    res[k] = '\0';
    return res;
}

int main() {
    int n = 0, cnt = 100;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%s", all[i]);
    for (int i = 1; i < n; i++) {
        if (strlen(getans(all[i], all[0])) < cnt) {
            ans1 = all[i];
            ans3 = getans(all[i], all[0]);
            cnt = strlen(ans3);
        }
    }
    printf("%s %s %d %s", all[0], ans1, cnt, ans3);
}
/*
7
computer
cmputer
cutr
ompute
put
cmputer
computerist
 */